package study.produceOrConsume;

import java.util.ArrayList;

// 多线程模拟生产者消费者模型
public class produceOrConsume {

	public static void main(String[] args) {
		ArrayList<Thread> consumeList = new ArrayList<>();
		ArrayList<Thread> produceList = new ArrayList<>();
		String flag= "abc";
		Consume consume = new Consume(flag);
		Produce produce = new Produce(flag);
		int produceInt = 5;
		int consumeInt = 5;
		
		// 建造produceInt个生产者线程
		for (int i = 0; i < produceInt; i++) {
			Thread thread = new Thread(produce);
			produceList.add(thread);
		}
		// 建造consumeInt个消费者
		for (int i = 0; i < consumeInt; i++) {
			Thread thread = new Thread(consume);
			consumeList.add(thread);
		}

		// 启动生产者线程
		for (int i = 0; i < produceList.size(); i++) {
			Thread temp = produceList.get(i);
			temp.start();
		}
		// 启动消费者线程
		for (int i = 0; i < consumeList.size(); i++) {
			Thread temp = consumeList.get(i);
			temp.start();
		}
	}
}
